package com.yuejian_06.yuejian_06.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.activity.ContestInfoActivity;
import com.yuejian_06.yuejian_06.bean.ActivityBean;
import com.yuejian_06.yuejian_06.bean.ContestBean;

import java.util.List;

/**
 * Created by __ZL__ on 2017/10/13.
 */

public class ContestAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public ContestAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.contestlistcardview,parent,false);
        return new ContestAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder,int position) {
        final ContestBean entity =(ContestBean) mDataList.get(position);
        if (null == entity)
            return;
        ContestAdapter.ViewHolder viewHolder = (ContestAdapter.ViewHolder) holder;
        viewHolder.contest_name.setText(entity.getContest_name());
        //String p = String.valueOf(entity.getPrice());
        if (!"".equals(entity.getContest_pic()))
            Picasso.with(mContext).load("http://10.0.2.2/yuejian/Public/acpics/"+entity.getContest_pic()).into(viewHolder.contest_pic);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,ContestInfoActivity.class);
                intent.putExtra("contest_id",entity.getContest_id()+"");
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView contest_name;
        private ImageView contest_pic;
        public ViewHolder(View itemView) {
            super(itemView);
            contest_name = (TextView) itemView.findViewById(R.id.contest_name);
            contest_pic = (ImageView) itemView.findViewById(R.id.contest_pic);
        }
    }
}
